package com.tuliyou.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuliyou.request.UpdateCurrentRequest;
import com.tuliyou.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

// UserMapper.java
@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT COUNT(*) FROM users WHERE username = #{username} AND is_deleted = 0")
    int countByUsername(@Param("username") String username);

    @Select("SELECT COUNT(*) FROM users WHERE email = #{email} AND is_deleted = 0")
    int countByEmail(@Param("email") String email);

    @Select("SELECT COUNT(*) FROM users WHERE phone = #{phone} AND is_deleted = 0")
    int countByPhone(@Param("phone") String phone);

    int updateCurrentUser(UpdateCurrentRequest request, @Param("userId") Long userId);

    @Update("update users set is_deleted = 1 where id = #{userId}")
    int logoff(Long userId);
}
